import axios from 'axios'

const service = axios.create({
  timeout: 60000,
  withCredentials: false,
  responseType: 'json'
})

service.interceptors.request.use(
  (config) => {
    config.headers.Authorization = 'Your token'
    return config
  },
  (error) => Promise.reject(error)
)

service.interceptors.response.use(
  (response) => {
    if (response.status === 401) {
      // 处理未授权
    }
    return response.data
  },
  (error) => Promise.reject(error)
)

export default function request(config) {
  return service({
    method: config.method || 'get',
    url: config.url,
    params: config.params,
    data: config.data
  })
}
